/**
 * D5Power Studio FPower 2D MMORPG Engine
 * 第五动力FPower 2D 多人在线角色扮演类网页游戏引擎
 * 
 * copyright [c] 2010 by D5Power.com Allrights Reserved.
 */ 
package com.D5Power.Render
{
	import com.D5Power.Objects.ActionObject;
	import com.D5Power.Objects.GameObject;
	
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 * 游戏渲染器
	 */ 
	public class Render
	{
		/**
		 * 缓冲区 
		 */ 
		public var d_buffer:BitmapData;
		
		public function Render()
		{
		}
		
		public function render(o:GameObject):void
		{
			/*
			var m:ActionObject= o as ActionObject;
			var drawRect:Rectangle =new Rectangle(m.currentFrame*m.graphics.frameWidth,0,m.graphics.frameWidth,m.graphics.frameWidth);	
			
			d_buffer.copyPixels(m.graphics.bitmap,drawRect,new Point(m.Pos.x-m.graphics.frameWidth/2,m.Pos.y-m.graphics.frameWidth/2),
				m.graphics.bitmapAlpha,new Point(drawRect.x,drawRect.y),true);
			*/
		}
		
		/**
		 * 填充素材
		 * @param		source	素材源
		 * @param		rect	渲染范围
		 * @param		p		坐标点
		 */ 
		protected function draw(source:BitmapData,rect:Rectangle,p:Point):void
		{
			if(source==null) return;
			try
			{
				d_buffer.lock();
				d_buffer.copyPixels(source,rect,p,null,null,true);
				d_buffer.unlock();
			}catch(e:Error){}
		}
		
		/**
		 * 渲染影子
		 * @param	o	gameObject
		 * @param	p	目前对象的渲染坐标
		 */ 
		protected function renderShadow(o:GameObject,p:Point):void
		{
			if(o.shadow==null) return;
			o.shadow.render(d_buffer,o,p);
		}
	}
}